<?php
/* SVN FILE: $Id$ */
/**
 * A custom component for automagically handling some AMF setup
 *
 * CakeAMF
 * Copyright 2007, Cake Software Foundation, Inc.
 *					1785 E. Sahara Avenue, Suite 490-204
 *					Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2007, Cake Software Foundation, Inc.
 * @link			http://trac.cakefoundation.org/amf CakeAMF
 * @package			amf
 * @subpackage		amf.controllers.components
 * @since			2007-05-27
 * @version			$Revision$
 * @modifiedby		$LastChangedBy$
 * @lastmodified	$Date$
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * AMF Component for enabling some automagic
 *
 * @package		amf
 * @subpackage	amf.controllers.components
 */
class AmfComponent extends Object {
/**
 * Startup
 *
 * @param object $controller
 * @return void
 */
	function initialize(&$controller) {
		$controller->isAmf = false;
		if (class_exists('amfdispatcher') && AmfDispatcher::active()) {
			$controller->isAmf = true;
			$controller->disableCache();
			$controller->view = 'Amf.Amf';
			$data = AmfDispatcher::data();
			if(is_array($data) || is_object($data)) {
				$data = array_pop($data);
				$controller->data = $data;
			}
		}
	}
/**
 * Intercept redirect and render amf response
 *
 * @param object $controller
 * @return void
 */
	function beforeRedirect(&$controller, $url, $status = null, $exit = false) {
		if ($controller->isAmf) {
			$controller->viewVars = am($controller->viewVars, array('Result'=> true));
			$controller->render();
			if($exit) {
				exit();
			}
		}
	}
}
?>